from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-20 14:02:11.921582
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 20, Feb, 2022
Time: 14:02:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.1937
Nobs: 573.000 HQIC: -48.6105
Log likelihood: 6775.82 FPE: 5.92876e-22
AIC: -48.8771 Det(Omega_mle): 5.07386e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347190 0.068463 5.071 0.000
L1.Burgenland 0.106309 0.041608 2.555 0.011
L1.Kärnten -0.110752 0.021663 -5.113 0.000
L1.Niederösterreich 0.188827 0.086706 2.178 0.029
L1.Oberösterreich 0.132969 0.085810 1.550 0.121
L1.Salzburg 0.254906 0.044031 5.789 0.000
L1.Steiermark 0.036539 0.058132 0.629 0.530
L1.Tirol 0.099818 0.046864 2.130 0.033
L1.Vorarlberg -0.069548 0.041356 -1.682 0.093
L1.Wien 0.020628 0.076270 0.270 0.787
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053466 0.147741 0.362 0.717
L1.Burgenland -0.038113 0.089789 -0.424 0.671
L1.Kärnten 0.041448 0.046747 0.887 0.375
L1.Niederösterreich -0.204160 0.187109 -1.091 0.275
L1.Oberösterreich 0.460930 0.185174 2.489 0.013
L1.Salzburg 0.282430 0.095018 2.972 0.003
L1.Steiermark 0.113345 0.125448 0.904 0.366
L1.Tirol 0.304108 0.101131 3.007 0.003
L1.Vorarlberg 0.025135 0.089245 0.282 0.778
L1.Wien -0.029089 0.164588 -0.177 0.860
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200014 0.034967 5.720 0.000
L1.Burgenland 0.088813 0.021251 4.179 0.000
L1.Kärnten -0.007420 0.011064 -0.671 0.502
L1.Niederösterreich 0.239572 0.044284 5.410 0.000
L1.Oberösterreich 0.161845 0.043826 3.693 0.000
L1.Salzburg 0.039764 0.022489 1.768 0.077
L1.Steiermark 0.026506 0.029691 0.893 0.372
L1.Tirol 0.081869 0.023935 3.420 0.001
L1.Vorarlberg 0.053466 0.021122 2.531 0.011
L1.Wien 0.117682 0.038954 3.021 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120937 0.034904 3.465 0.001
L1.Burgenland 0.043498 0.021213 2.051 0.040
L1.Kärnten -0.013086 0.011044 -1.185 0.236
L1.Niederösterreich 0.168569 0.044205 3.813 0.000
L1.Oberösterreich 0.337511 0.043748 7.715 0.000
L1.Salzburg 0.100541 0.022448 4.479 0.000
L1.Steiermark 0.110619 0.029637 3.732 0.000
L1.Tirol 0.090450 0.023892 3.786 0.000
L1.Vorarlberg 0.060944 0.021084 2.890 0.004
L1.Wien -0.020230 0.038884 -0.520 0.603
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122230 0.065780 1.858 0.063
L1.Burgenland -0.046555 0.039977 -1.165 0.244
L1.Kärnten -0.045345 0.020814 -2.179 0.029
L1.Niederösterreich 0.135116 0.083308 1.622 0.105
L1.Oberösterreich 0.165859 0.082447 2.012 0.044
L1.Salzburg 0.283875 0.042306 6.710 0.000
L1.Steiermark 0.057838 0.055854 1.036 0.300
L1.Tirol 0.156383 0.045027 3.473 0.001
L1.Vorarlberg 0.097154 0.039736 2.445 0.014
L1.Wien 0.076332 0.073281 1.042 0.298
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.081092 0.051275 1.582 0.114
L1.Burgenland 0.025836 0.031162 0.829 0.407
L1.Kärnten 0.053456 0.016224 3.295 0.001
L1.Niederösterreich 0.189054 0.064938 2.911 0.004
L1.Oberösterreich 0.329975 0.064266 5.134 0.000
L1.Salzburg 0.034566 0.032977 1.048 0.295
L1.Steiermark 0.005637 0.043538 0.129 0.897
L1.Tirol 0.120313 0.035098 3.428 0.001
L1.Vorarlberg 0.066035 0.030973 2.132 0.033
L1.Wien 0.095873 0.057122 1.678 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168629 0.062032 2.718 0.007
L1.Burgenland 0.005106 0.037700 0.135 0.892
L1.Kärnten -0.065930 0.019628 -3.359 0.001
L1.Niederösterreich -0.110868 0.078561 -1.411 0.158
L1.Oberösterreich 0.211600 0.077749 2.722 0.006
L1.Salzburg 0.054120 0.039895 1.357 0.175
L1.Steiermark 0.249233 0.052672 4.732 0.000
L1.Tirol 0.500804 0.042462 11.794 0.000
L1.Vorarlberg 0.065967 0.037471 1.760 0.078
L1.Wien -0.075729 0.069105 -1.096 0.273
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160065 0.068758 2.328 0.020
L1.Burgenland -0.003212 0.041787 -0.077 0.939
L1.Kärnten 0.062617 0.021756 2.878 0.004
L1.Niederösterreich 0.164863 0.087080 1.893 0.058
L1.Oberösterreich -0.053476 0.086180 -0.621 0.535
L1.Salzburg 0.207197 0.044221 4.685 0.000
L1.Steiermark 0.139294 0.058383 2.386 0.017
L1.Tirol 0.056894 0.047066 1.209 0.227
L1.Vorarlberg 0.147120 0.041535 3.542 0.000
L1.Wien 0.121666 0.076598 1.588 0.112
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.394237 0.040306 9.781 0.000
L1.Burgenland -0.003138 0.024496 -0.128 0.898
L1.Kärnten -0.021441 0.012753 -1.681 0.093
L1.Niederösterreich 0.200734 0.051046 3.932 0.000
L1.Oberösterreich 0.229557 0.050518 4.544 0.000
L1.Salzburg 0.037189 0.025922 1.435 0.151
L1.Steiermark -0.017244 0.034224 -0.504 0.614
L1.Tirol 0.091234 0.027590 3.307 0.001
L1.Vorarlberg 0.050727 0.024347 2.083 0.037
L1.Wien 0.041231 0.044902 0.918 0.358
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036316 0.101914 0.169228 0.136268 0.095548 0.081355 0.032222 0.210379
Kärnten 0.036316 1.000000 -0.027842 0.132340 0.048166 0.085488 0.443447 -0.067378 0.089156
Niederösterreich 0.101914 -0.027842 1.000000 0.309466 0.118827 0.269118 0.064969 0.151238 0.287144
Oberösterreich 0.169228 0.132340 0.309466 1.000000 0.214427 0.293554 0.167839 0.136067 0.234025
Salzburg 0.136268 0.048166 0.118827 0.214427 1.000000 0.123757 0.090554 0.104413 0.124007
Steiermark 0.095548 0.085488 0.269118 0.293554 0.123757 1.000000 0.134557 0.106158 0.031722
Tirol 0.081355 0.443447 0.064969 0.167839 0.090554 0.134557 1.000000 0.063908 0.151825
Vorarlberg 0.032222 -0.067378 0.151238 0.136067 0.104413 0.106158 0.063908 1.000000 -0.005334
Wien 0.210379 0.089156 0.287144 0.234025 0.124007 0.031722 0.151825 -0.005334 1.000000